<?
class DBLog {
    var $array_query = array();
    var $total_query = 0;
    var $total_time = 0;
    public function logQuery($sql, $time){
        $this->total_query++;
        $this->total_time += $time;
        $arr['sql'] = $sql;
        $arr['time'] = $time;
        $this->array_query[] = $arr;
    }
    public function showLog(){
        $html = '';
        if(defined('DEVELOP_ENVIROMENT') && DEVELOP_ENVIROMENT){
            $show_layout = getValue('show_layout','int','COOKIE',0);
            $html = '
        <div style="background:#333;color:#fff;font-size:14px;font-family:Tahoma;float : left;text-shadow: 1px 1px 4px #000;">
            <span onclick="dblog_show_layout('.(!$show_layout).');" style="color : #fff;padding : 5px;cursor : pointer;">'.(!$show_layout ? 'Show debug layout' : 'Hide debug layout').'</span>
            <script type="text/javascript">
                function dblog_show_layout(value){
                    document.cookie = "show_layout="+value;
                    window.location.reload();
                }
            </script>
            <table style="border : 1px solid #ccc;">
                <caption style="padding : 5px;font-size:13px;">
                    <b>Tổng query trên trang : '.$this->total_query.'</b>&nbsp;&nbsp;&nbsp;&nbsp;
                    <b>Tổng thời gian query : '.$this->total_time.'s</b>
                </caption>';
            foreach($this->array_query as $q){
                $html .=
                    '<tr style="border-bottom:1px dotted #aaa">
                        <td style="color:#fff;font-size: 14px;padding : 10px;font-family: Courier New, Courier">'.$q['sql'].'</td>
                        <td style="text-align: center;background:#fff;"><span style="padding:3px 10px;text-shadow:none;color:#ff5000">'.number_format($q['time'],14).'</span></td>
                    </tr>';
            }
            $html .= '</table>
        </div>';
        }
        return $html;
    }
}
unset($DBLog);
$DBLog = new DBLog();